package net.kingborn.core.entry;


import net.kingborn.core.util.StrKit;

import java.io.Serializable;

/**
 * 结果
 * 
 * @author David Chen
 *
 */
public class Result implements Serializable {

	private static final long serialVersionUID = 1L;
	
	public static final int CODE_SUCCESS = 0;
	public static final int CODE_FAILURE = 1;
	
	public static final String MESSAGE_SUCCESS = "success";
	public static final String MESSAGE_FAILURE = "failure";
	
	public static final String ERROR_MESSAGE_UNKNOWN_EXCEPTION = "未知错误";

	private boolean success;
	private String message;
	private int code;
	
	private Object data;
	
	public Result () {
		this.success = true;
		this.message = MESSAGE_SUCCESS;
		this.code = CODE_SUCCESS;
	}
	
    public Result(Object data) {
        this(true, CODE_SUCCESS, MESSAGE_SUCCESS, data);
    }
    
    public Result(boolean success, int code, String message) {
        this.success = success;
        this.code = code;
        this.message = StrKit.notBlank(message) ? message : ERROR_MESSAGE_UNKNOWN_EXCEPTION;

    }
    
    public Result(boolean success, int code, String message, Object data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "Result [success=" + success + ", message=" + message + ", code=" + code + ", data=" + data + "]";
	}

	/*public Result put(String key, Object value) {
		if (data == null) {
			data = new JSONObject();
		}
		JSONObject dataObj = (JSONObject) data;
		dataObj.put(key, value);

		return this;
	}*/
	
}
